From ddf774438ee4bf635d60a7630f2d2645db43c184 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 11 Dec 2015 01:18:11 -0600 Subject: [PATCH] Add convenience syntax to install current crate Essentially, `cargo install` becomes a synonym for `cargo install --path .`. This makes it easy and intuitive to install the crate in the current directory, as in the following: $ cargo build --release $ cargo install Note that this only works from the crate root. Closes #2142. --- src/bin/install.rs | 6 ++++++ src/cargo/ops/cargo_install.rs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bin/install.rs b/src/bin/install.rs index 141956179..3998111d9 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -75,6 +75,10 @@ crate has multiple binaries, the `--bin` argument can selectively install only one of them, and if you'd rather install examples the `--example` argument can be used as well. +As a special convenience, omitting the specification entirely will +install the crate in the current directory. That is, `install` is equivalent to +the more explicit `install --path .`. + The `--list` option will list all installed packages (and their versions). "; @@ -112,6 +116,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { SourceId::for_git(&url, gitref) } else if let Some(path) = options.flag_path { try!(SourceId::for_path(&config.cwd().join(path))) + } else if options.arg_crate == None { + try!(SourceId::for_path(&config.cwd())) } else { try!(SourceId::for_central(config)) }; diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index dc0223380..1aa516279 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -51,7 +51,11 @@ pub fn install(root: Option<&str>, .expect("path sources must have a valid path"); try!(select_pkg(PathSource::new(&path, source_id, config), source_id, krate, vers, - &mut |path| path.read_packages())) + &mut |path| path.read_packages()) + .chain_error(|| human(format!("`{}` is not a crate root; specify a \ + crate to install from crates.io, or \ + use --path or --git to specify an \ + alternate source", path.display())))) } else { try!(select_pkg(RegistrySource::new(source_id, config), source_id, krate, vers, -- 2.30.2